package com.gurun.base.utils;

import android.app.Activity;
import android.content.Context;
import android.support.annotation.IntDef;
import android.support.annotation.NonNull;
import android.support.annotation.StringRes;
import android.widget.Toast;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

public class ToastManager {

    private static Toast toast = null;

    public static void show(Context context, @StringRes int resId) {
        show(context, resId, Toast.LENGTH_SHORT);
    }

    public static void show(Context context, @StringRes int resId, @Duration int duration) {
        Toast.makeText(context, resId, duration).show();
    }

    public static void show(Context context, CharSequence text) {
        show(context, text, Toast.LENGTH_SHORT);
    }

    public static void show(Context context, CharSequence text, int duration) {
        Toast.makeText(context, text, duration).show();
    }


    public static void dismiss() {
        if (toast != null) {
            toast.cancel();
        }
    }

    @IntDef({Toast.LENGTH_SHORT, Toast.LENGTH_LONG})
    @Retention(RetentionPolicy.SOURCE)
    public @interface Duration {
    }
}
